<template>
  <view class="rows">
		<view class="top_bg">
			<image src="https://wt-1310486663.cos.ap-beijing.myqcloud.com/zgzj/jingzhang/static/images/bg1.png" mode="aspectFill" class="bg"></image>
			<!-- <image src="https://wt-1310486663.cos.ap-beijing.myqcloud.com/zgzj/jingzhang/static/images/logo.png" mode="aspectFill" class="logo"></image> -->
		</view>
		<view class="content">
			<view class="tabs">
				<view 
					@click="toPage(item.path)"
					class="tab-item" 
					v-for="(item, index) in tabs" 
					:key="index">
					<view class="top">
						<image :src="item.icon" mode="aspectFit"></image>
					</view>
					<text>{{item.text}}</text>
				</view>
			</view>
			<view class="notice">
				<view class="notice-title">
					<text>重要</text>
					<text>提醒</text>
				</view>
				<view class="notice-content"> 
					<view>{{attention}}</view>
				</view>
			</view>
			<view class="list">
				<view class="list-title">特色项目</view>
				<view class="list-content">
					<view class="list-item" v-for="item in list" :key="item.id">
						<view class="_left">
							<image :src="item.bannerImg" mode="aspectFill"></image>
						</view>
						<view class="_right">
							<view class="name">{{item.title}}</view>
							<text>{{item.content}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
  
		<uni-popup ref="popupRef" type="center" :is-mask-click="false">
			<view class="popup">
				<!-- <view class="close" @click="$refs.popupRef.close()">
					<u-icon name="close" color="#4f4f4f" size="38rpx"></u-icon>
				</view> -->
				<view class="popup-title">请求获取您的微信授权</view>
				<image src="https://wt-1310486663.cos.ap-beijing.myqcloud.com/zgzj/jingzhang/static/images/logo.png" mode="aspectFit"></image>
				<view class="login-btn">
					<view class="login cancel" @click="$refs.popupRef.close()">暂不登录</view>
					<view class="login" @click="login">授权登录</view>
				</view>
				<view class="agreement" @click="agreement = !agreement">
					<view class="dot" :class="{active: agreement}"></view>
					<text>同意《用户协议》《隐私政策》</text>
				</view>
			</view>
		</uni-popup>
		<user-info-modal ref="userInfoRef" @confirm="update"></user-info-modal>
	</view>
</template>

<script>
	import {code2SessionAPI, getAttention, getNewsList, updateUserInfoAPI} from '@/api/index.js'
	import {toPage, showToast} from '@/utils/tools.js'
	import {getToken, setToken} from '@/utils/storageToken.js'
	export default {
    data() {
      return {
				isLogin: false,
				agreement: false,
        tabs: [
					{
						icon: '/static/images/home1.svg',
						text: '票务预约',
						path: '/packages/ticket-reservation/ticket-reservation'
					},{
						icon: '/static/images/home2.svg',
						text: '京张文化'
					},{
						icon: '/static/images/home3.svg',
						text: '文创优选'
					},{
						icon: '/static/images/home4.svg',
						text: '铁路科普'
					},{
						icon: '/static/images/home5.svg',
						text: '数字游线'
					},{
						icon: '/static/images/home6.svg',
						text: '京张寄语'
					}
				],
				attention: '',
				list: []
      }
    },
		mounted() {
			this.hasLogin();
			this.getList();
		},
		methods: {
			toPage,
			hasLogin(){
				this.openid = getToken();
				if(!this.openid) return this.$refs.popupRef.open();
				this.isLogin = true;
			},
			login(){
				if(!this.agreement) return showToast('请先阅读并同意用户协议');
				uni.showLoading({
					title: '登录中',
					mask: true
				});
				uni.login({
					success: (res) => {
						code2SessionAPI(res.code).then(res => {
							this.$refs.popupRef.close();
							setToken(res.result);
							this.hasLogin();
							this.$refs.userInfoRef.open();
						})
					}
				})
			},
			update(e){
				updateUserInfoAPI(e).then(res => {
					this.$emit('update');
				})
			},
			getList(){
				getAttention().then(res => {
					this.attention = res.result;
				});
				getNewsList().then(res => {
					this.list = res.result;
				})
			}
		}
  }
</script>

<style lang="scss" scoped>
	.rows{
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		width: 100vw;
		height: 100%;
		background-color: #f7f7f7;
		overflow-y: auto;
		.top_bg{
			position: relative;
			width: 750rpx;
			height: 580rpx;
			.bg{
				width: 100%;
				height: 100%;
			}
			.logo{
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
				width: 255rpx;
				height: 255rpx;
			}
		}
		.content{
			position: relative;
			flex: 1;
			.tabs{
				display: grid;
				grid-template-columns: repeat(3, 1fr);
				transform: translateY(-30rpx);
				width: 688rpx;
				height: 346rpx;
				border-radius: 20rpx;
				margin: 0 auto;
				background: #fff;
				.tab-item{
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					.top{
						width: 72rpx;
						height: 72rpx;
						border-radius: 50%;
						margin-bottom: 10rpx;
						image{
							width: 100%;
							height: 100%;
						}
					}
					text{
						font-size: 30rpx;
						color: #b6b6b6;
					}
					&:nth-child(1){
						text{
							color: #333;
						}
					}
				}
			}
			.notice{
				display: flex;
				align-items: center;
				justify-content: space-between;
				background-color: #ffffff;
				border-radius: 10rpx;
				width: 688rpx;
				height: 70rpx;
				margin: 0 auto;
				padding: 10rpx 0;
				margin-bottom: 100rpx;
				.notice-title{
					line-height: 30rpx;
					height: 30rpx;
					font-size: $fs-30;
					color: #474747;
					padding: 0 15rpx;
					border-right: #000 1px solid;
					letter-spacing: 2rpx;
					text:first-child{
						color: red;
					}
				}
				.notice-content{
					font-size: $fs-30;
					color: #939393;
					flex: 1;
					padding: 0 15rpx;
					overflow: hidden;
					>view{
						animation: scroll 8s linear infinite;
					}
					@keyframes scroll {
						from{
							transform: translateX(100%);
						}
						to{
							transform: translateX(-100%);
						}
					}
				}
			}
			.list{
				width: 688rpx;
				margin: 0 auto;
				.list-title{
					color: #333;
					font-size: $fs-30;
					padding-left: 10rpx;
					border-left: 6rpx solid $primary;
					margin-bottom: 30rpx;
				}
				.list-content{
					border-radius: 20rpx;
					background-color: #fff;
					.list-item{
						display: flex;
						align-items: center;
						padding: 20rpx 30rpx;
						border-bottom: 1px solid #ededed;
						&:last-child{
							border-bottom: 0;
						}
						._left{
							width: 180rpx;
							height: 120rpx;
							background-color: $primary;
							border-radius: 20rpx;
							margin-right: 20rpx;
							overflow: hidden;
							image{
								width: 100%;
								height: 100%;
							}
						}
						._right{
							height: 100%;
							display: flex;
							flex-direction: column;
							justify-content: space-around;
							.name{
								color: #000;
								margin-bottom: 10rpx;
								font-size: $fs-30;
							}
							text{
								width: 400rpx;
								color: #a2a1a1;
								font-size: $fs-28;
								display: -webkit-box;
								-webkit-line-clamp: 2; /* 设置最大显示行数 */
								-webkit-box-orient: vertical;
								text-overflow: ellipsis;
							}
						}
					}
				}
			}
		}
	}
	.popup{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 540rpx;
		height: 520rpx;
		background-color: #fff;
		border-radius: 20rpx;
		.close{
			position: absolute;
			top: 30rpx;
			right: 30rpx;
		}
		.popup-title{
			color: $black;
			font-size: $fs-36;
		}
		image{
			width: 200rpx;
			height: 180rpx;
			margin: 30rpx 0;
		}
		.login-btn{
			display: flex;
			align-items: center;
			justify-content: center;
			.login{
				padding: 15rpx 35rpx;
				color: $white;
				font-size: $fs-30;
				font-weight: bold;
				border-radius: 20rpx;
				background-color: $primary;
				&.cancel{
					background-color: $grey;
					margin-right: 20rpx;
				}
			}
		}
		.agreement{
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 30rpx;
			.dot{
				position: relative;
				width: 30rpx;
				height: 30rpx;
				border-radius: 50%;
				border: 2rpx solid #000;
				margin-right: 10rpx;
				&.active::before{
					position: absolute;
					top: 50%;
					left: 50%;
					transform: translate(-50%, -50%);
					content: '';
					width: 15rpx;
					height: 15rpx;
					border-radius: 50%;
					background-color: #000;
				}
			}
			text{
				color: $black;
				font-size: $fs-30;
			}
		}
	}
</style>
